package com.gali.juc;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: gali
 * @Date: 2022-08-19 15:27
 * @Description:
 */
class Phone{
    public static synchronized void sendEmail(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("---sendEmail---");
    }
    public synchronized void sendSMS(){
        System.out.println("---sendSMS---");
    }
    public void hello(){
        System.out.println("---hello---");
    }
}
public class Lock8 {
    public static void main(String[] args) {
        Phone phone = new Phone();
        Phone phone1 = new Phone();

        new Thread(()->{
            phone.sendEmail();
        },"t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
//            phone.sendSMS();
//            phone.hello();
            phone1.sendSMS();
        },"t2").start();
    }
}
